package org.prime;

import java.math.BigInteger;

public class BigIntegerExtender {


	public static BigInteger increment(BigInteger obj){
		return obj.add(BigInteger.ONE); 
	}
	public static BigInteger increment(BigInteger obj,BigInteger x){
		return obj.add(x); 
	}
	
	public static BigInteger sqrt(BigInteger n) {
		  BigInteger a = (BigInteger) BigInteger.ONE;
		  BigInteger b = new BigInteger(n.shiftRight(5).add(new BigInteger("8")).toString());
		  while(b.compareTo(a) >= 0) {
			  BigInteger mid = new BigInteger(a.add(b).shiftRight(1).toString());
		    if(mid.multiply(mid).compareTo(n) > 0) b = (BigInteger) mid.subtract(BigInteger.ONE);
		    else a = (BigInteger) mid.add(BigInteger.ONE);
		  }
		  return (BigInteger) a.subtract(BigInteger.ONE);
		}

	public static Boolean divisibleBy(BigInteger obj,BigInteger divider){
		if (obj.mod(divider).compareTo(BigInteger.ZERO) == 0 )
			return true;
		return false;
	}

}
